import { Nodes } from '@knno/dom';
import { Toggle as UIToggle } from '../components/toggle/toggle';
import { JSXProps } from '@knno/dom/jsx';
import { AttrCheck, isBool, isStr, jsxBuild } from './utils';

export { UIToggle };

interface ToggleProps extends JSXProps<UIToggle> {
	checked?: boolean;
	text?: string;
	value?: unknown;
	disabled?: boolean;
}

const ATTRS: AttrCheck = {
	checked: isBool,
	text: isStr,
	disabled: isBool,
};

export function Toggle(props: ToggleProps, children: Nodes[]): UIToggle {
	return jsxBuild(new UIToggle(), props, children, ATTRS);
}
